# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_test(
    name = "acl_table_test",
    srcs = ["acl_table_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:pd",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//p4rt_app/utils:table_utility",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "api_access_test",
    srcs = ["api_access_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "arbitration_test",
    srcs = ["arbitration_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googleapis//google/rpc:status_cc_proto",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "action_set_test",
    srcs = ["action_set_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "fixed_l3_tables_test",
    srcs = ["fixed_l3_tables_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:pd",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "forwarding_pipeline_config_test",
    srcs = ["forwarding_pipeline_config_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi/utils:annotation_parser",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/sonic/adapters:fake_sonic_db_table",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/utils:table_utility",
        "//sai_p4/instantiations/google:clos_stage",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_p4info_fetcher_cc",
        "//sai_p4/instantiations/google/test_tools:table_entry_generator",
        "//sai_p4/instantiations/google/test_tools:table_entry_generator_helper",
        "//sai_p4/tools:p4info_tools",
        "@com_github_google_glog//:glog",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
        "@sonic_swss_common//:common",
    ],
)

cc_test(
    name = "p4_programs_test",
    srcs = ["p4_programs_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi/utils:annotation_parser",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "packetio_test",
    size = "small",
    srcs = ["packetio_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:pd",
        "//p4_pdpi/string_encodings:hex_string",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/sonic:fake_packetio_interface",
        "//p4rt_app/sonic:packetio_interface",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "debug_data_dump_test",
    srcs = ["debug_data_dump_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/event_monitoring:config_db_queue_table_event",
        "//gutil/gutil:io",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "port_name_and_id_test",
    srcs = ["port_name_and_id_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "cpu_queue_name_and_id_test",
    srcs = ["cpu_queue_name_and_id_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:p4_runtime_session",
	"//p4rt_app/event_monitoring:config_db_queue_table_event",
        "//p4rt_app/sonic/adapters:fake_sonic_db_table",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_googletest//:gtest_main",
        "@sonic_swss_common//:common",
    ],
)

cc_test(
    name = "front_panel_queue_name_and_id_test",
    srcs = ["front_panel_queue_name_and_id_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//p4rt_app/event_monitoring:config_db_queue_table_event",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_googletest//:gtest_main",
        "@sonic_swss_common//:common",
    ],
)

cc_test(
    name = "packet_replication_table_test",
    srcs = ["packet_replication_table_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "response_path_test",
    srcs = ["response_path_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/sonic/adapters:fake_sonic_db_table",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/time",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "role_test",
    srcs = ["role_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/fixed:p4_roles",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:p4_roles",
        "//sai_p4/instantiations/google:sai_p4info_cc",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:optional",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "state_verification_test",
    srcs = ["state_verification_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "vrf_table_test",
    srcs = ["vrf_table_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_grpc_service",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "grpc_behavior_test",
    timeout = "short",
    srcs = ["grpc_behavior_test.cc"],
    tags = ["exclusive"],
    deps = [
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/sonic:fake_packetio_interface",
        "//p4rt_app/sonic:redis_connections",
        "//p4rt_app/sonic/adapters:fake_warm_boot_state_adapter",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_googletest//:gtest_main",
    ],
)

# go/golden-test-with-coverage
cc_test(
    name = "p4_constraints_test_runner",
    srcs = ["p4_constraints_test_runner.cc"],
    linkstatic = True,
    tags = ["exclusive"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/p4runtime:p4runtime_impl",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "resource_limits_test",
    srcs = ["resource_limits_test.cc"],
    deps = [
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "utf8_validity_test",
    srcs = ["utf8_validity_test.cc"],
    deps = [
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:pd",
        "//p4_pdpi/string_encodings:hex_string",
        "//p4rt_app/tests/lib:p4runtime_component_test_fixture",
        "//p4rt_app/tests/lib:p4runtime_request_helpers",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cmd_diff_test(
    name = "p4_constraints_test",
    actual_cmd =
        " | ".join([
            "$(execpath :p4_constraints_test_runner)",
            # Strip unnecessary lines for golden testing.
            "sed '1,/^###/d'",  # Strip everything up to a line beginning with '###'.
            "sed '/^\\[/d'",  # Strip every line beginning with '['.
        ]),
    expected = "golden_outputs/p4_constraints_test.expected",
    tools = [
        ":p4_constraints_test_runner",
    ],
)
